var happyReaderText = {
    title:'',
	content:'',
	textData:'',
    inited:false,
    fontSize:16,
	minPageWidth:600,
	maxPageWidth:(window.screen.width/100|0)*100,
	textSkinBgWrapShown:false,
	textPageWidthWrapShown:false,
	specialSite:function(doc){
        var doc = doc || document, host = doc.location.hostname, title;
        function deal(title, items, type){
            title = title.trim();
            var str = (type == 'string') ? items : '' ;
            if (type != 'string') {
                for (var i = 0, item; item = items[i++];) {
                    str += item.outerHTML;
                }
            }
			happyReaderText.title = title;
			happyReaderText.content = str;
            return title ? '<p style=\"font-weight:900;font-size:24px;text-align:center\">'+title+'</p>'+happyReaderText.share.get()+'<hr/>'+str : str;
        }
		if (/.*.ifeng.com$/i.test(host)){
            title = doc.getElementById('artical_topic').innerHTML;
            return deal(title, doc.getElementById('artical_real').getElementsByTagName('p'));
        }
        if (/.*.bitauto.com/i.test(host)){
            title = doc.getElementsByClassName('con_main')[0].getElementsByTagName('a')[0].innerHTML;
            return deal(title, doc.getElementsByClassName('con_main')[0].getElementsByTagName('p'));
        }
        if (/.*.people.com.cn/i.test(host)) {
            title = doc.getElementById('p_title').innerHTML;
            return deal(title, doc.getElementById('p_content').innerHTML, 'string');
        }
    },
    getData:function(nextPageDoc){
        var specialSiteContent = this.specialSite(nextPageDoc);
        if (specialSiteContent){
            this.textData = specialSiteContent;
			return specialSiteContent;
        }

        function getRect(element){
            if (!element.rect) {
                element.rect = element.getBoundingClientRect();
                element.rect.offsetLeft = element.rect.left + element.ownerDocument.body.scrollLeft;
                element.rect.offsetTop = element.rect.top + element.ownerDocument.body.scrollTop
            }
            return element.rect;
        }
        
        function getStyle(element){
            if (!element.computedStyle) 
                element.computedStyle = getComputedStyle(element);
            return element.computedStyle;
        }
        
        function getFontSize(element){
            var fontSize = getStyle(element).fontSize;
            if (!fontSize) 
                return 0;
            return parseInt(fontSize, 10);
        }
        
        function isVisible(element, isDeeplyCheck){
            var style = getStyle(element);
            if (style.display == "none" || style.visibility == "hidden") 
                return false;
            var rect = element.getBoundingClientRect();
            if (rect.width <= 0 || rect.height <= 0) 
                return false;
            if (isDeeplyCheck && document.body.scrollTop == 0) {
                if (rect.top + rect.height / 2 < window.innerHeight) {
                    if (rect = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2)) 
                        for (; rect != element && (rect = rect.parentElement););
                    if (rect != element) 
                        return false;
                }
            }
            return true;
        }
        
        function compareHost(url1, url2){
            var re = /https?:\/\/(?:\w+\.)*(\w+\.\w+)/;
            host1 = re.exec(url1)[1];
            host2 = re.exec(url2)[1];
            return host1 === host2;
        }
        
        function isValidChar(charCode){
            switch(charCode){
                case (charCode < 4352):
                    return false;
                case (charCode >= 12352 || charCode <= 12447):
                case (charCode >= 12448 || charCode <= 12543):
                case (charCode >= 19968 || charCode <= 40959):
                case (charCode >= 13056 || charCode <= 13311):
                case (charCode >= 65072 || charCode <= 65103):
                case (charCode >= 63744 || charCode <= 64255):
                case (charCode >= 11904 || charCode <= 12031):
                case (charCode >= 12288 || charCode <= 12351):
                case (charCode >= 13312 || charCode <= 19903):
                case (charCode >= 12800 || charCode <= 13055):
                case (charCode >= 12688 || charCode <= 12703):
                case (charCode >= 12784 || charCode <= 12799):
                case (charCode >= 12544 || charCode <= 12591):
                case (charCode >= 12704 || charCode <= 12735):
                case (charCode >= 12032 || charCode <= 12255):
                case (charCode >= 12592 || charCode <= 12687):
                case (charCode >= 4352 || charCode <= 4607):
                case (charCode >= 44032 || charCode <= 55215):
                    return true;
                default:
                    return false;
            }
        }
        
        function documentClass(doc){
            this.contentDocument = doc;
            this.content = undefined;
            this.headingElement = undefined;
            this.title = undefined;
            this.j = undefined;
            this.bestElement = undefined;
            this.o = 1;
            this.getBestElement = function(){
                var candidates = this.getCandidates();
                candidates.sort(function(e1, e2){
                    return e2.getScore() - e1.getScore();
                });
                if (!candidates || !candidates.length) 
                    return null;
                for (var c = 2, ele = null; c-- > 0;){
                    ele = candidates.shift();
                    if (ele.checkSpaceScore() || ele.textScore() < 4) 
                        return null;
                    if (ele.checkHrScore() || ele.checkImportantTagScore()) {
                        ele = null;
                    }else {
                        var style = getStyle(ele.element);
                        ele.isLTR = style ? style.direction === "ltr" : true;
                        break;
                    }
                }
                return ele;
            };
            this.O = function(){
                if (!this.bestElement){
                    return null;
                } 
                  
                for (var ele=this.bestElement.element, i=0; i < 3 && ele; i++, ele=ele.parentNode) {
                    var elements = this.filterCandidateByRelation(ele);
                    if (elements && elements.length) {
                        elements = elements.sort(function(e1, e2){
                            return e2.getScore() - e1.getScore()
                        });
                        
                        var style = getStyle(E(this));
                        for (var i=0, element; element=elements[i++];){
                            if (!element || !element.getScore()){
                                break;
                            }
                            
                            if (!element.checkSpaceScore() && !element.checkHrScore() && !element.checkImportantTagScore()){
                                if (!(getRect(element.element).height < 50 && getRect(this.bestElement.element).width != getRect(element.element).width)){
                                    var elementStyle = getStyle(element.element);
                                    if (!(elementStyle.fontFamily !== style.fontFamily || elementStyle.fontSize !== style.fontSize)){
                                        return element;
                                    }
                                }
                            }
                        }
                    }
                }
                return null;
            };
            this.getCandidates = function(){
                var tagSet = ['HTML', 'HEAD', 'META', 'TITLE','SCRIPT', 'STYLE', 'LINK', 'IMG', 'FORM', 'INPUT', 'BUTTON', 
                    'TEXTAREA', 'SELECT', 'OPTION', 'LABEL', 'IFRAME', 'UL', 'OL', 'LI', 'DD', 'DT', 'A', 'OBJECT', 'PARAM',
                    'EMBED', 'NOSCRIPT', 'EM', 'B', 'STRONG', 'I', 'INS', 'BR', 'HR', 'PRE', 'H1', 'H2','H3', 'H4','H5','CITE'],
                    timeLimit = Date.now() + 1E3, 
                    elements = this.contentDocument.getElementsByTagName("*"), 
                    candidates = [];
                    
                for (var element, i=0; element=elements[i++];) {
                    if (tagSet.indexOf(element.tagName) == -1) {
                        (element = this.sizeFilter(element, this.contentDocument)) && candidates.push(element);
                        if (Date.now() > timeLimit) {
                            candidates = [];
                            break;
                        }
                    }
                }
                return candidates;
            };
            this.filterCandidateByRelation = function(element){
                if (!this.bestElement) 
                    return [];
                
                if (!element) 
                    element = this.bestElement.element;
            
                var candidates=[],
                    tagSet = ['BODY', 'HTML', 'HEAD', 'META', 'TITLE','SCRIPT', 'STYLE', 'LINK', 'IMG', 'FORM', 'INPUT', 'BUTTON', 
                    'TEXTAREA', 'SELECT', 'OPTION', 'LABEL', 'IFRAME', 'UL', 'OL', 'LI', 'DD', 'DT', 'A', 'OBJECT', 'PARAM',
                    'EMBED', 'NOSCRIPT', 'EM', 'B', 'STRONG', 'I', 'INS', 'BR', 'HR', 'PRE', 'H1', 'H2','H3', 'H4','H5','CITE'], 
                    elements = this.contentDocument.evaluate("preceding-sibling::*/descendant-or-self::*", element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
                
                for (var element, i=0; element=elements.snapshotItem(i++);){
                    if (tagSet.indexOf(element.tagName) == '-1') {
                        (element = this.positionFilter(element, this.bestElement, this.contentDocument)) && candidates.push(element);
                    }
                }
                return candidates;
            };
            this.sizeFilter = function(element, contentDocument){
                if (!isVisible(element, false))
                    return null;
                if (getRect(element).width < 300 || getRect(element).height < 200) 
                    return null;
                return new elementClass(element, contentDocument)
            };
            this.positionFilter = function(element, bestElement, contentDocument){
                if (!isVisible(element, false)) 
                    return null;
        
                var elementRect = getRect(element),bestElementRect = getRect(bestElement.element);
                if (elementRect.right <= bestElementRect.left || elementRect.left >= bestElementRect.right) 
                    return null;
                if (elementRect.top >= bestElementRect.top) 
                    return null;
        
                return new elementClass(element, contentDocument);
            };
            this.getTitle = function(){
                F(this);
                var titleRe = /header|title|headline/i, titleCandidate = this.j, headingElement;
                titleCandidate = getRect((titleCandidate ? titleCandidate.element : null) || E(this));
                var titleLeft = titleCandidate.offsetLeft + titleCandidate.width / 2, titleTop = titleCandidate.offsetTop, titleValidTop = titleTop;
                
                if ((newElement = this.contentDocument.elementFromPoint(titleLeft, titleTop - 150)) && newElement.tagName === "IMG") {
                    var newElementRect = getRect(newElement);
                    if (newElementRect.height >= 300 && newElementRect.width >= titleCandidate.width * 0.5){
                        titleValidTop = newElementRect.offsetTop;
                    }
                }
                
                var style = getStyle(E(this)),
                    docTitle = this.contentDocument.title.toLowerCase(),
                    elements = this.contentDocument.querySelectorAll("h1, h2, h3, h4, h5, .headline, .article_title, #hn-headline");
                
                for (var i=0, element, text; element=elements[i++];){
                    text=element.innerText;
                    if (text.length >= 8 && isVisible(element, true)) {
                        var elementStyle = getRect(element),
                            elementLeft = elementStyle.offsetLeft + elementStyle.width / 2,
                            leftOffset = elementLeft - titleLeft,
                            topOffset = element.offsetTop - titleValidTop,
                            offset = Math.sqrt(leftOffset * leftOffset + topOffset * topOffset),
                            relativeOffset = Math.max(500 - offset, 0);
                        
                        if (offset < 500 && elementStyle.width > titleCandidate.width * 0.5 && elementLeft > titleCandidate.left && elementLeft < titleCandidate.right) {
                            var fontSize = getFontSize(element);
                            if (fontSize >= 12) {
                                relativeOffset *= fontSize / 16;
                                if (fontSize > parseInt(style.fontSize, 10) * 1.4) {
                                    relativeOffset *= 1.25;
                                }
                                if (titleRe.test(element.className) || titleRe.test(element.id)) {
                                    relativeOffset *= 1.5;
                                }
                                if (docTitle.length > 0) {
                                    var tmpTitle = docTitle, tmpText = text.toLowerCase(), titleLen = 0, group = [], w = 0;
                                    if (tmpTitle.length === 0) {
                                        titleLen = tmpText.length;
                                    }else {
                                        if (tmpText.length === 0) {
                                            titleLen = tmpTitle.length;
                                        }
                                        else {
                                            for (var j = 0; j <= tmpTitle.length; j++) {
                                                group[j] = [];
                                                group[j][0] = j;
                                            }
                                            for (var j = 0; j <= tmpText.length; j++) {
                                                group[0][j] = j;
                                            }
                                            for (var k = 1; k <= tmpTitle.length; k++) {
                                                for (j = 1; j <= tmpText.length; j++) {
                                                    w = (tmpTitle.charAt(k - 1) == tmpText.charAt(j - 1)) ? 0 : 1;
                                                    group[k][j] = Math.min(group[k - 1][j] + 1, group[k][j - 1] + 1, group[k - 1][j - 1] + w);
                                                    if (k > 1 && j > 1 && tmpTitle.charAt(k - 1) == tmpText.charAt(j - 2) && tmpTitle.charAt(k - 2) == tmpText.charAt(j - 1)) {
                                                        group[k][j] = Math.min(group[k][j], group[k - 2][j - 2] + w);
                                                    }
                                                }
                                            }
                                            titleLen = group[tmpTitle.length][tmpText.length];
                                        }
                                    }
                                    relativeOffset += (1 - titleLen / docTitle.length) * relativeOffset * 0.2;
                                }
                                if (!headingElement || relativeOffset > headingElement.offset) {
                                    headingElement = element;
                                    headingElement.offset = relativeOffset;
                                    headingElement.text = text;
                                }
                            }
                        }
                    }
                }
                
                if (headingElement) {
                    this.title = headingElement.text;
                    this.headingElement = headingElement;
                }
                if (!this.title) {
                    this.title = this.contentDocument.title;
                    this.headingElement = null;
                }
                
                return this.title;
            };
            
            this.getArticle = function(element, contentElement){
                getTitle(this);
                function e(step){
                    if (q) 
                        q += step;
                    if (tableLevel) 
                        tableLevel += step;
                    if (fontStyleLevel) 
                        fontStyleLevel += step;
                    if (fontWeightLevel) 
                        fontWeightLevel += step;
                }
                
                var removeTags = {FORM: 1, IFRAME: 1, SCRIPT: 1, STYLE: 1, LINK: 1}, 
                    candidateTags = {DIV: 1, TABLE: 1, OBJECT: 1, UL: 1}, 
                    italicTags = {I: 1, EM: 1}, 
                    boldTags = {B: 1, STRONG: 1, H1: 1, H2: 1, H3: 1, H4: 1, H5: 1, H6: 1}, 
                    candidates = [], q = 0, tableLevel = 0, fontStyleLevel = 0, fontWeightLevel = 0, curElement = element, curContentElement = contentElement;
                
                for (;curElement;) {
                    var garbage = null, tagName = curContentElement.tagName, curStyle = getStyle(curElement);
                    curContentElement.g = curElement;
                    if (tagName in removeTags || curElement === this.headingElement) 
                        garbage = curContentElement;
                    
                    if (!garbage) {
                        if (tagName != "PARAM" && curStyle.display === "none") 
                            garbage = curContentElement;
                    }
                    if (!garbage && curContentElement.childElementCount === 1) {
                        for (var child = curContentElement.firstElementChild; child.childElementCount === 1;) 
                            child = child.firstElementChild;
                        if (child.tagName == "BR" && !/\S/.test(curContentElement.innerText)) 
                            garbage = curContentElement;
                    }
                    if (!garbage) {
                        if (/comment/i.test(curContentElement.id + " " + curContentElement.className)) 
                            garbage = curContentElement;
                        var host = this.contentDocument.location.host;
                        if (!garbage && host.substr(host.length - 13, 13) == "wikipedia.org" && curContentElement.className == "editsection") 
                            garbage = curContentElement;
                    }
                    if (!garbage) {
                        if (tagName === "DIV" && curContentElement.parentNode) {
                            var maybeCandidates = curElement.querySelectorAll("a, blockquote, dl, div, img, ol, p, pre, table, ul");
                            if (!(q || curStyle["float"] !== "none") && !maybeCandidates.length) {
                                var parentElement = curContentElement.parentNode;
                                for (var pElement = this.contentDocument.createElement("p"); curContentElement.firstChild;) 
                                    pElement.appendChild(curContentElement.firstChild);
                                parentElement.replaceChild(pElement, curContentElement);
                                curContentElement = pElement;
                                curContentElement.g = curElement;
                                tagName = curContentElement.tagName;
                            }
                        }
                        curContentElement.parentNode && (tagName in candidateTags) && candidates.push(curContentElement);
                        if (curElement !== element && tagName !== "IMG" && !q && curStyle["float"] !== "none" && (getRect(curElement).height >= 40 || curElement.childElementCount > 1)) 
                            q = 1;
                        var curElementAttributes = curContentElement.attributes;
                        for (var j=0, node; node=curElementAttributes[j++];) {
                            var I = node.nodeName;
                            if (/class|style|align/i.test(I) || I == "align" && /justify/i.test(node.nodeValue)) {
                                curContentElement.removeAttribute(I);
                                j--;
                            }
                        }
                        if (!fontStyleLevel && curStyle.fontStyle !== "normal") {
                            if (!(tagName in italicTags)) 
                                curContentElement.style.fontStyle = curStyle.fontStyle;
                            fontStyleLevel = 1;
                        }
                        if (!fontWeightLevel && curStyle.fontWeight !== "normal") {
                            if (!(tagName in boldTags)) 
                                curContentElement.style.fontWeight = curStyle.fontWeight;
                            fontWeightLevel = 1;
                        }
                        if (q) {
                            if (q === 1) {
                                if (getRect(curElement).width === getRect(element).width) {
                                    curContentElement.setAttribute("class", "float full-width");
                                }else {
                                    curContentElement.setAttribute("class", "float " + curStyle["float"]);
                                    curContentElement.style.clear = curStyle.clear;
                                }
                            }
                            var curElementWidth = curElement.style.getPropertyValue("width");
                            if (curElementWidth) {
                                curContentElement.style.width = curElementWidth;
                            }else {
                                if (I = window.getMatchedCSSRules(curElement, "", true)) {
                                    for (var j = I.length - 1; j >= 0; j--) {
                                        if (curElementWidth = I[j].style.getPropertyValue("width")) {
                                            curContentElement.style.width = curElementWidth;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (q === 1 && !curElementWidth) {
                                curContentElement.style.width = getRect(curElement).width + "px";
                            }
                        }
                        
                        if (tagName === "TABLE") {
                            tableLevel = tableLevel || 1;
                        }else if (tagName === "IMG") {
                            curContentElement.removeAttribute("border");
                            curContentElement.removeAttribute("hspace");
                            curContentElement.removeAttribute("vspace");
                            curContentElement.removeAttribute("align");

                            if (q) {
                                curContentElement.style["float"] = curStyle["float"];
                                curContentElement.style.clear = curStyle.clear;
                            }else {
                                var curElementStyle = getRect(curElement);
                                if (curElementStyle.width < 128 && curElementStyle.height < 128) {
                                    curContentElement.setAttribute("class", "tinyImage");
                                }else {
                                    curElementStyle.width / element.clientWidth > 0.6 && curContentElement.setAttribute("class", "largeImage");
                                }
                                if (curStyle["float"] !== "none") {
                                    curContentElement.setAttribute("class", "float " + curStyle["float"]);
                                    curContentElement.style["float"] = curStyle["float"];
                                    curContentElement.style.clear = curStyle.clear;
                                }
                            }
                            curContentElement.setAttribute("src", curContentElement.src);
                            curContentElement.g.m = curContentElement;
                            curContentElement.g.addEventListener("load", this.modifyImgSrc, false);
                        }else if (tagName === "FONT") {
                            curContentElement.removeAttribute("size");
                            curContentElement.removeAttribute("face");
                            curContentElement.removeAttribute("color");
                        }else if (tagName === "A" && curContentElement.parentNode) {
                            var hrefAttributes = curContentElement.getAttribute("href");
                            if (hrefAttributes && hrefAttributes.length && (hrefAttributes[0] === "#" || hrefAttributes.substring(0, 11) === "javascript:")) {
                                if (!tableLevel && !curContentElement.childElementCount && curContentElement.parentElement.childElementCount === 1) {
                                    this.contentDocument.evaluate("text()", curContentElement.parentElement, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength || (garbage = curContentElement);
                                }
                                if (!garbage) {
                                    var spanElement = this.contentDocument.createElement("span");
                                    if (curContentElement.childElementCount === 1 && curContentElement.firstElementChild.tagName === "IMG") {
                                        var firstChild = curContentElement.firstElementChild;
                                        firstChild.width > 32 && firstChild.height > 32 && spanElement.setAttribute("class", "image-anchor");
                                    }
                                    for (spanElement.className || spanElement.setAttribute("class", "text-anchor"); curContentElement.firstChild;) {
                                        spanElement.appendChild(curContentElement.firstChild);
                                    }
                                    curContentElement.parentNode.replaceChild(spanElement, curContentElement);
                                    curContentElement = spanElement;
                                }
                            }
                            if (curContentElement.href) {
                                curContentElement.setAttribute("href", curContentElement.href);
                                curContentElement.setAttribute("target", "_new");
                            }
                        }else if (tagName === "SPAN" && curStyle.display === "block") {
                                curContentElement.style.display = "block";
                        }
                    }
                    
                    if (!garbage && curElement.firstElementChild) {
                        curElement = curElement.firstElementChild;
                        curContentElement = curContentElement.firstElementChild;
                        e(1);
                    }else {
                        for (var da; curElement !== element && !(da = curElement.nextElementSibling);) {
                            curElement = curElement.parentElement;
                            curContentElement = curContentElement.parentElement;
                            e(-1);
                        }
                        if (curElement === element) {
                            garbage && garbage.parentElement && garbage.parentElement.removeChild(garbage);
                            break
                        }
                        curElement = da;
                        curContentElement = curContentElement.nextElementSibling;
                        if (q === 1) 
                            q = 0;
                        if (tableLevel === 1) 
                            tableLevel = 0;
                        if (fontStyleLevel === 1) 
                            fontStyleLevel = 0;
                        if (fontWeightLevel === 1) 
                            fontWeightLevel = 0;
                    }
                    
                    if (garbage && garbage.parentElement) {
                        do {
                            var garbageParentElement = garbage.parentElement;
                            if (garbageParentElement) {
                                garbageParentElement.removeChild(garbage);
                                garbage = garbageParentElement;
                            }
                        }
                        while (garbageParentElement != curElement.parentElement && garbageParentElement.childElementCount == 0 && !/\S/.test(garbageParentElement.innerText))
                    }
                }
                for (var j = candidates.length - 1, d; j >= 0; j--) {
                    d = candidates[j];
                    if (d.parentNode && this.isGarbage(d, d.g, element)) {
                        garbage = d;
                        garbage.parentElement.removeChild(garbage);
                    }
                }
                var floatElements = contentElement.querySelectorAll(".float");
                for (var j = 0, d, f, h, k; d=floatElements[j++];) {
                    f = d.querySelectorAll("a, span.image-anchor");
                    h = d.querySelectorAll("span.text-anchor");
                    f = d.parentNode && h.length > f.length;
                    if (!f) {
                        h = d.querySelectorAll("embed, object").length;
                        k = d.g.querySelectorAll("embed, object").length;
                        if (!h && k) 
                            f = true
                    }
                    f && d.parentNode.removeChild(d);
                }
                return contentElement;
            };
            this.modifyImgSrc = function(b){
                b = b.target;
                if (b.m && b.m.src != b.src) 
                    b.m.src = b.src
            };
            this.isGarbage = function(candidate, c, e){
                var positiveRe = /article|body|content|entry|page|pagination|post|text/i, 
                    negativeRe = /comment|combx|disqus|contact|foot|link|masthead|media|meta|promo|related|scroll|shoutbox|sponsor|tags|widget|share|pagination/i,
                    score = 0,
                    tagName = candidate.tagName;
                if (tagName !== "OBJECT" && tagName !== "EMBED") {
                    for (var isValidNode=false, j=0, node, nType; node=candidate.childNodes[j++];){
                        nType = node.nodeType;
                        if (nType === Node.ELEMENT_NODE || nType === Node.TEXT_NODE && /\S/.test(node.nodeValue)){
                            isValidNode = true;
                            break;
                        }
                    }
                    if (!isValidNode) {
                        return true;
                    }
                }
                
                if (c) {
                    positiveRe.test(c.className) && h++;
                    positiveRe.test(c.id) && h++;
                    negativeRe.test(c.className) && h--;
                    negativeRe.test(c.id) && h--;
                }
                if (score < 0) 
                    return true;

                if (tagName === "UL") {
                    if (c.querySelector("iframe") && c.querySelector("script")) 
                        return true;
                    return false;
                }
                if (tagName === "OBJECT") {
                    var b, 
                        h = candidate.querySelector("embed[src]"), 
                        c = /youtube|vimeo|dailymotion|livestream\.com|viddler\.com/, 
                        thisHref = this.contentDocument.location.href;
                    
                    if (h && c.test(h.src)) 
                        return false;
                    if ((b = candidate.getAttribute("data")) && c.test(b)) 
                        return false;
                    if ((h && compareHost(thisHref, h.src)) || compareHost(thisHref, b)) 
                        return false;
                    return true;
                }
                if (c.childElementCount === 1) {
                    var child = c.firstElementChild;
                    if (child.tagName === "A" && child.getElementsByTagName("img").length == 0) 
                        if (getFontSize(child) / getFontSize(e) < 0.75) 
                            return true;
                }
                if (candidate.childElementCount === 1) {
                    if (candidate.firstElementChild.tagName === "A") 
                        return false;
                }
                
                var f = candidate.querySelectorAll("img");
                e = f.length;
                d = 0;
                if (e) {
                    for (var l = k = 0; l < e; l++) {
                        n = f[l].g;
                        if (isVisible(n, false)) {
                            q = getRect(n);
                            k += q.width / e * (q.height / e);
                            q = q.width * q.height;
                            if (!compareHost(this.contentDocument.location.href, n.src) || q < 16384) 
                                d++
                        }
                    }
                    if (k > 4E4) 
                        return false
                }
                if (!this.J(candidate, 10)) 
                    return false;
                l = candidate.querySelectorAll("p").length;
                f = candidate.querySelectorAll("br").length;
                l = l + Math.floor(f / 2);
                if (d > l) 
                    return true;
                if (c.querySelectorAll("li a[href]").length > l) 
                    return true;
                if (candidate.querySelectorAll("input").length / l > 0.33) 
                    return true;
                if (candidate.textContent.trim().length < 25 && (e == 0 || e > 1 && d > 0)) 
                    return true;
                if (candidate.querySelector("embed")) 
                    return true;
                l = this.D(candidate);
                if (score >= 1 && l > 0.5) 
                    return true;
                if (score < 1 && l > 0.2) 
                    return true;
                if (tagName === "TABLE") {
                   var b = candidate.innerText.trim().length, c = c.innerText.trim().length;
                    if (b <= c * 0.5) 
                        return true;
                }
                return false;
            };
            this.J = function(b, c){
                for (var e = 0, d = b.textContent, f = -1; e < c && (f = d.indexOf(",", f + 1)) >= 0;) 
                    e++;
                return e < c;
            };
            this.D = function(b){
                var c = b.textContent.trim().length;
                if (!c) 
                    return 0;
                b = b.querySelectorAll("a");
                for (var e = 0, d = 0; d < b.length; d++) 
                    e += b[d].textContent.trim().length;
                return e / c;
            };
        }

        function F(docObj){
            if (!docObj.bestElement) {
                docObj.bestElement = docObj.getBestElement();
                docObj.j = docObj.O();
            }
            return docObj.bestElement;
        }
        
        function E(docObj){
            return (docObj = F(docObj)) ? docObj.element : null
        }
        
        function getContent(docObj){
            if (docObj.content !== undefined) {
                return docObj.content;
            }
            var element = E(docObj);
            if (!element) {
                return null;
            }
            docObj.content = element.cloneNode(true);
            docObj.content = docObj.getArticle(element, docObj.content);
            if (docObj.j) 
                (element = docObj.getArticle(docObj.j.element, docObj.j.element.cloneNode(true))) && docObj.content.insertBefore(element, docObj.content.firstChild);
            return docObj.content;
        }
        
        function getTitle(docObj){
            return docObj.title || docObj.getTitle();
        }
        
        function elementClass(element, contentDocument){
            this.element = element;
            this.contentDocument = contentDocument;
            this.isLTR = true;
            this.textFactor = 0;
            this.computeAllParagraphsScore = function(){
                for(var score=0, i=0, paragraph; paragraph=this.allParagraphs[i++];){
                    score += this.computeParagraphsScore(paragraph);
                }
                return score;
            };
            this.getWeight = function(){
                for (var positiveRe = /article|entry|post|body|column|main|content/i, negativeRe = /comment|combx|disqus|foot|header|menu|rss|shoutbox|sidebar|sponsor/i, weight = 1, element = this.element; element; element = element.parentElement) {
                    var str = element.getAttribute("id");
                    if (str) {
                        if (positiveRe.test(str)) 
                            weight += 0.4;
                        if (negativeRe.test(str)) 
                            weight -= 0.8
                    }
                    if ((str = element.className) && typeof str === "string") {
                        if (positiveRe.test(str)) 
                            weight += 0.4;
                        if (negativeRe.test(str)) 
                            weight -= 0.8
                    }
                }
                return weight;
            };
            this.getTextFactor = function(){
                if (this.textFactor === 0) {
                    this.textFactor = 1;
                    if (this.allParagraphs && this.allParagraphs.length > 0) {
                        var validCharCount = 0, text = this.allParagraphs[0].nodeValue.trim(), minLen = Math.min(text.length, 10);
                        for (var i = 0; i < minLen; i++) {
                            isValidChar(text.charCodeAt(i)) && validCharCount++;
                        }
                        
                        if (validCharCount >= minLen / 2) {
                            this.textFactor = 3;
                        }
                    }
                }
                return this.textFactor;
            };
            this.textScore = function(){
                this.getTextFactor();
                return this.getScore() * this.textFactor;
            };
            this.getScore = function(){
                return this.score * this.weight;
            };
            this.getAllParagraphs = function(element){
                var result = [], elementSet = ['A', 'DD', 'DT', 'OL', 'UL', 'OPTION', 'PRE', 'SCRIPT', 'STYLE', 'IFRAME'];
                if (!element) 
                    return result;
        
                element = this.contentDocument.evaluate("text()|*/text()|*/li/text()|*/strong/text()|*/span/text()|*/font/text()|blockquote/text()|blockquote/*/text()|*/blockquote/text()|*/blockquote/*/text()|div/p/text()|div/p/index/text()", element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
                for (var i=0, node; node=element.snapshotItem(i++);) {
                    if (elementSet.indexOf(node.parentNode.tagName) == '-1') {
                        if (/\S/.test(node.nodeValue)) {
                            var parentNode = node.parentElement, grandParentNode = parentNode.parentElement || {};
                            /comment/i.test(parentNode.id + " " + parentNode.className + " " + grandParentNode.id + " " + grandParentNode.className) || result.push(node)
                        }
                    }
                }
                return result;
            };
            this.computeParagraphsScore = function(text){
                var len = text.length, weight = 1;
                if (!text || len < 20) 
                    return 0;
                
                for (text = text.parentNode; text && text != this.element;) {
                    weight -= 0.1;
                    text = text.parentNode
                }
                return Math.pow(len * weight, 1.25)
            };
            this.getSpaceScore = function(){
                var garbageSpace = 0, 
                    fontSizeSum = 0,
                    fontSizeFactor = 16,
                    validParagraphsCount = 0,
                    thisElementValidSpace = 0,
                    thisElementRect = getRect(this.element), 
                    thisElementSpace = thisElementRect.width * thisElementRect.height,
                    validImageWidth = thisElementRect.width * 0.15,
                    validImageSize = thisElementSpace * 0.2,
                    thisImgs = this.element.querySelectorAll("img"),
                    thisOthers = this.contentDocument.evaluate("*[name()!='img']", this.element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        
                for (var i=0, img; img=thisImgs[i++];){
                    if (img.width >= validImageWidth && img.height > 50){
                        var imgSize = img.width * img.height;
                        if (imgSize < validImageSize){
                            garbageSpace += imgSize;
                        }
                    }
                }

                if (thisOthers.snapshotLength > 2){
                    for (var i=0, item; item=thisOthers.snapshotItem(i++);){
                        if (/comment/i.test(item.id + " " + item.className) || !/\S/.test(item.innerText) && item.getElementsByTagName("img").length == 0){
                            var rect = getRect(item);
                            garbageSpace += rect.width * rect.height;
                        }
                    }
                }
                
                thisElementValidSpace = thisElementSpace - garbageSpace;
                
                for (var i=0, item, parentNode; item=this.allParagraphs[i++];){
                    if (parentNode = item.parentNode){
                        fontSizeSum += getFontSize(parentNode);
                        validParagraphsCount++;
                    }
                }
                
                if (validParagraphsCount > 0){
                    fontSizeFactor = fontSizeSum / validParagraphsCount;
                }
                return this.getScore() / thisElementValidSpace * 1E3 * (fontSizeFactor / 16) * this.getTextFactor();
            };
            this.checkSpaceScore = function(){
                return (this.getSpaceScore() < 1.5) ? true : false;
            };
            this.checkHrScore = function(){
                var validHRCount = 0,
                    HRs = this.element.querySelectorAll("hr"), 
                    thisElementRect = getRect(this.element), 
                    validWidth = thisElementRect.width * 0.7;
        
                for (var i=0, hr; hr=HRs[i++];){
                    hr.clientWidth > validWidth && validHRCount++;
                }
                
                return (validHRCount > 0 && thisElementRect.height / validHRCount < 180) ? true : false;
            };
            this.checkImportantTagScore = function(){
                var importantTags = this.contentDocument.evaluate("(h1|h2|h3|h4|h5|h6|*/h1|*/h2|*/h3|*/h4|*/h5|*/h6)[a]", this.element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
                    thisElementRect = getRect(this.element),
                    validHeight = thisElementRect.height * 0.05,
                    validTagCount = 0;
        
                if (importantTags.spanshotLength > 2){
                    for (var i=0, tag, tagRect; tag=importantTags.snapshotItem(i++), tagRect = getRect(tag);){
                        tagRect.top - thisElementRect.top > validHeight && thisElementRect.bottom - tagRect.bottom > validHeight && validTagCount++;
                    }
                    if (validTagCount > 0 && thisElementRect.height / validTagCount < 300)
                        return true;
                }
                return false;
            };
            this.allParagraphs = this.getAllParagraphs(element);
            this.score = this.computeAllParagraphsScore();
            this.weight = this.getWeight();
        }
		
        var doc = new documentClass(nextPageDoc || document), contentElement = getContent(doc);
        if (contentElement){
            //remove empty childNode
            contentElement.innerHTML = contentElement.innerHTML.replace(/<!--(.*?)-->/igm,'').replace(/\u3000+/g,'');
			
			var imgWidthMaxLimit = parseInt(this.getArticlePageWidth(this.getTextPageWidth()))*0.8|0, 
                imgs = contentElement.getElementsByTagName('img');

            for(var idx in imgs){
                var img = imgs[idx];
                if (img.width > 100 || img.height > 100){
                    img.className = 'largeImage';
                    if (img.width > imgWidthMaxLimit){
                        img.width = imgWidthMaxLimit;
                        img.removeAttribute('height');
                    }
                }
            }
			
			function addP() {
				var lastStr = unknownStrs[unknownStrs.length-1];
				if (lastStr) {
					var tagName = lastStr.substring(1,lastStr.indexOf('>')).toLowerCase();
					if (['blockquote','code','h1','h2','h3','h4'].indexOf(tagName) > -1) {
						return ;
					}
                    unknownStrs[unknownStrs.length - 1] = '<p>' + lastStr.replace('<p>','').replace('</p>','') + '</p>';
                }
			}
			
			var unknownStrs = [], unknownLastIdx = 0, unknownFlag = false;
			for(var i=0, node; node=contentElement.childNodes[i++];){
				if (typeof(node.innerText) == 'undefined'){
                    if (typeof(node.nodeValue) == 'string' && node.nodeValue.trim() != '') {
						if (!unknownFlag){
							addP();
							unknownStrs.push(node.nodeValue);
						}else {
							unknownFlag = false;
							unknownStrs[unknownStrs.length-1] += node.nodeValue;
						}
                    }else{
                        contentElement.removeChild(node);
                        i--;
                    }
				}else if (node.tagName == 'A'){
					unknownFlag = true;
					unknownLastIdx = i;
					var strA = node.outerHTML;
					if (unknownStrs.length == 0){
						unknownStrs.push(strA);
					}else {
						unknownStrs[unknownStrs.length-1] += strA;
					}
                }else if (['IMG'].indexOf(node.tagName) == -1 && node.innerText.trim() == '' && node.innerHTML.indexOf('<img') == -1){
					for(var j=0, child;child=node.childNodes[j++];){
                        if (child.tagName == 'IMG' || (child.innerHTML && child.innerHTML.toLowerCase().indexOf('<img') >= 0)){
							continue;
                        }
                        node.removeChild(child);
                        j--;
                    }
                    if (!node.innerHTML) {
                        contentElement.removeChild(node);
                        i--;
                    }
				}else {
					addP();
					node.removeAttribute('id');
					unknownStrs.push(node.outerHTML);
				}
            }
			
			if (unknownFlag){
				if (typeof(unknownStrs[unknownLastIdx]) == 'undefined'){
					unknownStrs[unknownLastIdx] = '';
				}else {
					unknownStrs[unknownLastIdx] = '<p>'+unknownStrs[unknownLastIdx]+'</p>';
				}
			}
			
            this.title = doc.title;
			this.content = unknownStrs.join('');
			this.textData = doc.title ? '<p class="title">'+doc.title+'</p>'+this.share.get()+'<hr/>'+this.content : this.content;
			return this.textData;
		}
    },
    init:function(){
	    var connection = chrome.extension.connect();
		connection.postMessage({"action":"getUserInfo"});
	    connection.onMessage.addListener(function(msg, conn){
	        userInfo = msg.userInfo;
	        $('#happyReaderHeaderAD').html(_m("otherModeHeaderAD").replace('uid', userInfo ? (100000+parseInt(userInfo.uid)) : '-1'));
	    });
        happyReader.setUserConfig("viewMode","text");
        if (this.inited)return ;
        this.inited = true;
        
        var textPageWidth = this.getTextPageWidth(),
		    articlePageWidth = this.getArticlePageWidth(textPageWidth),
		    textSkinBg = this.getTextSkinBg(),
		    minHeight = document.height - 45,
		    articleStyle = "style='min-height:"+(minHeight - 45)+"px;background:"+textSkinBg+";width:"+articlePageWidth+"'",
		    html = "<article "+articleStyle+"><p>"+_m("noText")+"</p></article>",
			textBar = "<span id='textLarger'>"+_m('textBarLarger')+"</span><span id='textSmaller'>"+_m('textBarSmaller')+"</span><span id='textSkin'>"+_m('textBarSkin')+"</span><span id='textPageWidth'>"+_m('textBarPageWidth')+"</span><span id='textCollect'>"+_m('textBarCollect')+"</span>",
			textSkinBgWrap = "<div id='textSkinWrap' class='triangle-border'><u id='textSkin1'></u><u id='textSkin2'></u><u id='textSkin3'></u><u id='textSkin4'></u><u id='textSkin5'></u><u id='textSkin6'></u></div>",
			textPageWidthWrap = "<div id='textPageWidthWrap' class='triangle-border'><input type='range' min='"+this.minPageWidth+"' max='"+this.maxPageWidth+"' value='"+textPageWidth+"' id='textPageWidthScrollBar'/> <i id='textPageWidthValue'>"+textPageWidth+"</i><input id='textPageWidthInput' maxlength=4/></div>",
			textBarClose = "<close id='textBarClose'>X</close>";

        this.textData && (html = "<article "+articleStyle+"><page>1/<totalPage>1</totalPage></page>"+this.textData+"</article><div id='textBar'>"+textBar+textSkinBgWrap+textPageWidthWrap+textBarClose+"</div>");
        $('#textCanvas').css({'left':0,'minHeight':minHeight+'px'}).html(html);
		
		this.updateFontSize(this.getFontSize());
		
        $('#happyReader_weibo').attr({onclick:function(){_gaq.push(['_trackEvent', 'share::weibo', 'share']);}});
        $('#happyReader_tsohu').attr({onclick:function(){_gaq.push(['_trackEvent', 'share::tsohu', 'share']);}});
        $('#happyReader_qqweibo').attr({onclick:function(){_gaq.push(['_trackEvent', 'share::qqweibo', 'share']);}});
        $('#happyReader_renren').attr({onclick:function(){_gaq.push(['_trackEvent', 'share::renren', 'share']);}});
        $('#happyReader_google').attr({onclick:function(){_gaq.push(['_trackEvent', 'share::google', 'share']);}});
		$('#textLarger').attr({onclick:function(){happyReaderText.setTextLarger()}});
		$('#textSmaller').attr({onclick:function(){happyReaderText.setTextSmaller()}});
		$('#textSkin').attr({onclick:function(){happyReaderText.textSkinsCtrl()}});
		$('#textSkin1').attr({onclick:function(){happyReaderText.setTextSkinBg(this.id)}});
		$('#textSkin2').attr({onclick:function(){happyReaderText.setTextSkinBg(this.id)}});
		$('#textSkin3').attr({onclick:function(){happyReaderText.setTextSkinBg(this.id)}});
		$('#textSkin4').attr({onclick:function(){happyReaderText.setTextSkinBg(this.id)}});
		$('#textSkin5').attr({onclick:function(){happyReaderText.setTextSkinBg(this.id)}});
		$('#textSkin6').attr({onclick:function(){happyReaderText.setTextSkinBg(this.id)}});
		$('#textPageWidth').attr({onclick:function(){happyReaderText.textPageWidthWrapCtrl()}});
		$('#textPageWidthScrollBar').attr({onchange:function(){happyReaderText.textPageWidthScrollBarOnChangeHandle(this.value)},onmouseup:function(){happyReaderText.setTextPageWidth(this.value)}});
        $('#textPageWidthValue').attr({onclick:function(){happyReaderText.showTextPageWidthInput(this)}});
		$('#textPageWidthInput').attr({onblur:function(){happyReaderText.hideTextPageWidthInput(this.value)},onkeydown:function(e){if (e.keyCode == 13){happyReaderText.hideTextPageWidthInput(this.value)}}});
		$('#textBarClose').attr({onclick:function(){$('#textBar').attr({onmouseover:function(){$(this).hide()}}).hide();}});
		$('#textCollect').attr({onclick: function(){
			this.innerHTML = _m('textBarSaving');
			this.style.color = '#fff';
			this.onclick = null;
			var content = '', 
			    intro = happyReaderText.content.replace(/<[^>]*>/g, '').replace(/&nbsp;/g, '').substr(0, 140) + '...', 
				articles = document.querySelectorAll('#textCanvas > article');
			
			for (var idx in articles) {
				if (articles[idx].innerHTML){
					var arti = articles[idx].cloneNode(true),
					    c = arti.querySelectorAll('p:not([class="title"]), div, h2');
                    for(var i in c){
                        c[i].style && c[i].removeAttribute('style');
                    }
					content += '<article>' + arti.innerHTML + '</article>';
					arti = null;
				};
			}
			content &&
			chrome.extension.sendRequest({
				'action': 'sendTextToCloud',
				'title': happyReaderText.title,
				'url': location.href,
				'intro': intro,
				'content': content
			}, function(response){
				$('#textCollect').html(response.suc == 1 ? _m('textBarDone') : response.msg||_m('textBarFailed'));
			});
		}});
		this.textData && happyReader.getNextPageContent();
		_gaq.push(['_trackEvent', 'HRTextUrl', location.href]);
    },
    share:{
        get:function(){
            var str = '<p class="share">';
            str += this.t_sina();
            str += this.t_qq();
            str += this.t_sohu();
            str += this.renren();
            str += this.g();
            return str+='</p>';
        },
        getCode:function(siteUri){
            return "javascript:void(window.open('"+siteUri+"'+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'', 'width=680, height=630, top="+(window.screen.height-630)/2+", left="+(window.screen.width-680)/2+", toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no'))";
        },
        t_sina:function(){
            return '<a href="'+this.getCode('http://v.t.sina.com.cn/share/share.php?appkey=1810717743&url=')+'"><img id="happyReader_weibo" src="http://weibo.com/favicon.ico" width=16 /></a>';
        },
        t_sohu:function(){
            return '<a href="'+this.getCode('http://t.sohu.com/third/post.jsp?link=')+'"><img id="happyReader_tsohu" src="http://t.sohu.com/favicon.ico" width=16/></a>';
        },
        t_qq:function(){
            return '<a href="'+this.getCode('http://v.t.qq.com/share/share.php?url=')+'"><img id="happyReader_qqweibo" src="http://mat1.gtimg.com/www/mb/favicon.ico" width=16 /></a>';
        },
        renren:function(){
            return '<a href="'+this.getCode('http://share.xiaonei.com/share/buttonshare.do?link=')+'"><img id="happyReader_renren" src="http://a.xnimg.cn/imgpro/chat/app_menu_logo.png" width=16 /></a>';
        },
        g:function(){
            return '<a href="'+this.getCode('http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=')+'"><img id="happyReader_google" src="http://www.google.cn/favicon.ico" width=16 /></a>'
        }
    },
	checkModeValid:function(){
		return this.textData && this.textData.length > 50;
	},
	_setTextSkinSetting:function(){
		chrome.extension.connect().postMessage({'action':'setTextSkin', 'textSkin':setting_textSkin});
	},
	_setFontSize:function(size){
		var fontSize = setting_textSkin.fontSize = size+'px';
		this.updateFontSize(fontSize);
		this._setTextSkinSetting();
		this.hideTextSkinBgs();
		this.hideTextPageWidth();
    },
	updateFontSize:function(fontSize){
		var c = document.querySelectorAll('article>p:not([class="title"]), article>div, article>h2');
        for(var idx in c){
            c[idx].style && (c[idx].style.fontSize = fontSize);
        }
	},
	getFontSize:function(){
		return setting_textSkin.fontSize || '16px';
	},
	setTextLarger:function(){
		this._setFontSize(++this.fontSize);
	},
	setTextSmaller:function(){
		this._setFontSize(--this.fontSize);
	},
	showTextSkinBgs:function(){
		$('#textSkinWrap').css({opacity:1,top:'-68px'});
		$('#textSkin').css({color:'#fff'});
		happyReaderText.textSkinBgWrapShown = true;
		this.hideTextPageWidth();
		_gaq.push(['_trackEvent', 'textSkins::show', 'showTextSkins']);
	},
	hideTextSkinBgs:function(){
		if (!happyReaderText.textSkinBgWrapShown) {
			return;
		}
		
		$('#textSkinWrap').css({opacity:0,top:'-16px'});
		$('#textSkin').css({color:'#3e67cf'});
		happyReaderText.textSkinBgWrapShown = false;
	},
	textSkinsCtrl:function(){
		this.textSkinBgWrapShown ? this.hideTextSkinBgs() : this.showTextSkinBgs();
	},
	getTextSkinBg:function(){
        return setting_textSkin.bg || '#fff';
    },
	setTextSkinBg:function(id){
		var color = setting_textSkin.bg = window.getComputedStyle(document.getElementById(id), null).backgroundColor;
		this.updateTextSkinBg(color);
		this._setTextSkinSetting();
		_gaq.push(['_trackEvent', 'textSkins::set_'+color, 'setTextSkins']);
	},
	updateTextSkinBg:function(color){
		var a = document.getElementsByTagName('article');
        for(var idx in a){
            a[idx].style && (a[idx].style.backgroundColor = color); 
        }
	},
	showTextPageWidth:function(){
		$('#textPageWidthWrap').css({opacity:1,top:'-68px'});
        $('#textPageWidth').css({color:'#fff'});
        happyReaderText.textPageWidthWrapShown = true;
		this.hideTextSkinBgs();
        _gaq.push(['_trackEvent', 'textPageWidth::show', 'showTextPageWidth']);
	},
	hideTextPageWidth:function(){
		if (!happyReaderText.textPageWidthWrapShown) {
            return;
        }
		$('#textPageWidthWrap').css({opacity:0,top:'-16px'});
        $('#textPageWidth').css({color:'#3e67cf'});
        happyReaderText.textPageWidthWrapShown = false;
	},
	textPageWidthWrapCtrl:function(){
		this.textPageWidthWrapShown ? this.hideTextPageWidth() : this.showTextPageWidth();
	},
	getArticlePageWidth:function(value){
		return parseInt(value) - 130 + 'px';
	},
	getTextPageWidth:function(){
		return setting_textSkin.pageWidth || 800;
	},
	setTextPageWidth:function(width){
		setting_textSkin.pageWidth = width;
        this._setTextSkinSetting();
        _gaq.push(['_trackEvent', 'textPageWidth::set_'+width, 'setTextPageWidth']);
	},
	updateTextPageWidth:function(width){
		var width = this.getArticlePageWidth(width),
		    a = document.getElementsByTagName('article');
        for(var idx in a){
            a[idx].style && (a[idx].style.width = width); 
        }
	},
	resetTextPageWidthValue:function(value){
		var width = parseInt(value),
		    oldWidth = this.getTextPageWidth();
			
		width = Math.min(width, this.maxPageWidth);
		width = Math.max(width, this.minPageWidth);
		if (width == oldWidth){
			return
		}
			
		$('#textPageWidthScrollBar').val(width);
		this.textPageWidthScrollBarOnChangeHandle(width);
	},
	textPageWidthScrollBarOnChangeHandle:function(value){
		$('#textPageWidthValue').html(value);
		this.updateTextPageWidth(value);
	},
	showTextPageWidthInput:function(self){
		$('#textPageWidthInput').val($(self).hide().html()).css({display:'inline'})[0].select();
	},
	hideTextPageWidthInput:function(value){
		$('#textPageWidthInput').hide();
		$('#textPageWidthValue').css({display:'inline-block'});
		happyReaderText.resetTextPageWidthValue(value);
		happyReaderText.setTextPageWidth(value);
	},
	sendMail:function(){}
};